﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Navigation;
using Studio77.SuperLink.Entities;
using Studio77.SuperLink.Pages;
using Studio77.SuperLink.Core;

namespace Studio77.SuperLink.Views
{
    public partial class StageItemView : UserControl
    {
        int index;

        public StageItemView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(StageItemView_Loaded);
            this.Tap += new EventHandler<GestureEventArgs>(StageItemView_Tap);
        }

        void StageItemView_Tap(object sender, GestureEventArgs e)
        {
            if (((StageItemViewModel)this.DataContext).IsClickEnable)
            {
                int i = ((StageItemViewModel)this.DataContext).Index;
                //点击，进入关卡
                this.StoryboardClick.Begin();
                StageManager.Instance.CurrentStageIndex = i;
                StagePage.CurrentStagePage.NavigateTo(
                        new Uri("/Pages/GamePage.xaml?stageCode=" + StageManager.Instance.CurrentStageType
                        + "_" + i, UriKind.Relative));

        //        //test
        //        StageManager.Instance.CurrentStageType = "3";
        //        StageManager.Instance.CurrentStageIndex = 28;
        //        StagePage.CurrentStagePage.NavigateTo(
        //new Uri("/Pages/GamePage.xaml?stageCode=3_28", UriKind.Relative));

                //播放音效
                SoundManager.PlayEffect(SoundManager.Click_Button);
            }
        }

        void StageItemView_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= new RoutedEventHandler(StageItemView_Loaded);
            //播放动画
            index = ((StageItemViewModel)this.DataContext).Index;
            this.StoryboardShowing.BeginTime = TimeSpan.FromMilliseconds(((index % 5) + 1) * 100);
            this.StoryboardShowing.Begin();
        }
    }
}
